//Sample of use of PageFactory
//Be aware of how to initiate a Page object using PageFactory
//http://code.google.com/p/selenium/wiki/PageFactory


package PageFactory;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.Assert;

public class UsePageFactory {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		WebDriver driver = new FirefoxDriver();
		
		driver.get("http://www.google.com.au");
		
		
		GoogleHomePage homePage = PageFactory.initElements(driver, GoogleHomePage.class);
		//Check if google logo exists
		Assert.assertTrue(homePage.logo.isDisplayed());
		
		//Check if footer displayed
		Assert.assertTrue(homePage.footer.isDisplayed());
		//Search for cheese
		homePage.searchFor("cheese");
		
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		
		googleSearchResultPage searchresultpage = PageFactory.initElements(driver, googleSearchResultPage.class);
		//Check if google home link exists
		Assert.assertTrue(searchresultpage.googleHomeLink.isDisplayed());
		//Return to home page
		searchresultpage.returnTogoogleHomepage();

		driver.quit();
	}

}
